
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" type="text/css" th:href="@{/assets/css/layui.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/assets/css/view.css}"/>
    <title>管理后台-新闻管理</title>
</head>
<body class="layui-view-body">
<div class="layui-content">
    <div class="layui-row">
        <div class="layui-card">
            <div class="layui-card-body" id="vueContainer">
            <div class="layui-form layui-form-item">
                <form th:action="@{/a/u/newbook}" method="post">
                    <div class="layui-inline">
                        <div class="layui-form-mid">新闻标题:</div>
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" name="title" autocomplete="off" class="layui-input">
                        </div>
                        <!--<div class="layui-form-mid">邮箱:</div>
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" name="email" autocomplete="off" class="layui-input">
                        </div>-->
                        <input type="submit" class="layui-btn layui-btn-blue" value="查询"></input>
                        <input type="reset" class="layui-btn layui-btn-primary" value="重置"></input>
                    </div>
                </form>
            </div>




                <a th:href="@{/a/u/news/form}"><button class="layui-btn layui-btn-blue"><i class="layui-icon">&#xe654;</i>新增</button></a>
                <table class="layui-table" id="newsTable">
                    <colgroup>
                        <col width="150">
                        <col width="200">
                        <col>
                    </colgroup>
                    <thead>
                    <tr>
                        <th>新闻标题</th>
                        <th>新闻类别</th>
                        <th>发布时间</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="item:${newslist}">
                        <td th:text="${item.title}"></td>
                        <td th:text="${item.category} =='0' ? '公司新闻': '行业新闻' "></td>
                        <td th:text="${#dates.format(item.releaseTime,'yyyy-MM-dd HH:mm:ss')}"></td>


                        <td style="color: red; font-size: 16px"th:text="${item.delIdent} =='0' ? '已发布': '未发布' "></td>
                        <td>
                            <a href="#" th:href="@{/a/u/news/form(id=${item.id})}" class="layui-btn layui-btn-sm">编辑新闻</a>
                           <!-- <a href="#"  th:href="@{contextPath +'/f/news/form?id=' + ${item.id}}" class="layui-btn layui-btn-sm">修改</a>-->
                            <!--<a href="#" @click="del(${item.id})" class="layui-btn layui-btn-sm layui-btn-danger">删除</a>-->
                            <!--<a href="#" th:href="@{/f/delete(id=${item.id})}" class="layui-btn layui-btn-sm layui-btn-danger">删除</a>-->
                            <a href="#" th:onclick="|deleteNews(${item.id})|" th:style="${(item.delIdent == 0 ) ? '' : 'display:none'}"
                               class="layui-btn layui-btn-sm layui-btn-danger">下架新闻</a>
                        </td>
                    </tr>
                    </tbody>
                </table>
                <!--分页导航-->
                <div id="pagination"></div>
            </div>
        </div>
    </div>
</div>
<script th:src="@{/assets/layui.all.js}"></script>

<script type="text/javascript" th:src="@{/js/contactus/jquery-3.2.1.js}"></script>
<script th:src="@{https://cdn.staticfile.org/vue/2.2.2/vue.min.js}"></script>
<script th:inline="javascript">
    var count = [[${count}]];//总记录数
    var curr = [[${curr}]];//当前页
    var contextPath = [[${#request.getContextPath()}]]; //获取当前应用路径
</script>
<script type="text/javascript">
    function deleteNews(id){
        if(!confirm("确定下架这个新闻？")){
            return;
        }
        window.location.href = contextPath + "/a/u/deleteNews?id="+id;
    }
</script>
<script type="text/javascript">
    //使用layui分页
    layui.use('laypage', function(){
        var laypage = layui.laypage;

        //执行一个laypage实例
        laypage.render({
            elem: 'pagination' //注意，这里的 data 是 ID，不用加 # 号
            ,count: count //数据总数，从服务端得到
            ,curr: curr
            ,limit: 4
            ,jump: function(obj, first){
                //obj包含了当前分页的所有参数，比如：
                // console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                // console.log(obj.limit); //得到每页显示的条数

                //首次不执行
                if(!first){
                    window.location.href = contextPath + "/a/u/newbook?pageIndex=" + (obj.curr) + "&pageSize=" + obj.limit
                }
            }
        });
    });





    //删除
   /* function del(${item.id}) {
        //询问框
        layer.confirm('确认删除？', {
            btn: ['必须的','算了吧'] //按钮
        }, function(){
            $.ajax({
                type: 'POST',
                url: contextPath + '/f/news/delete',
                data: {"id":id},
                async: false,//一定设置同步，目的为对totalCount赋值
                success: function (data) {
                    layer.msg('保存成功', {
                        icon: 1,time:1000
                    },function () {
                        layer.load(1);
                        window.location.reload(true);
                    });
                }
            });

        }, function(){
            layer.msg('取消成功', {
                time: 1000, //20s后自动关闭
            });
        });
    }*/
</script>
</body>
</html>